Deploying infrastructure in a consistent, reliable manner is difficult — it requires people to follow documented procedures without taking any undocumented shortcuts. Plus, it can be difficult to deploy infrastructure out-of-hours when less staff are available. AWS CloudFormation changes this by defining infrastructure in a template that can be automatically deployed — even on an automated schedule.
Throughout, I gained hands-on experience deploying and editing CloudFormation stacks. It was an interactive experience that required me to consult documentation to discover how to define resources within a CloudFormation template.
The work demonstrated how to:
I began by deploying a CloudFormation stack that creates a VPC.
First, I downloaded the CloudFormation template (task1.yaml) by right-clicking the link and opened it in a Text Editor (not a Word Processor).
Looking through the file, I noticed several sections:
I noted that the template was written in YAML format, commonly used for configuration files, and that the format was important, including indents and hyphens. I also learned that CloudFormation templates can be written in JSON as well.
To launch the CloudFormation stack:
The stack entered the CREATE_IN_PROGRESS status. I clicked the Events tab and scrolled through the listing, seeing the activities performed by CloudFormation in reverse order, such as starting and completing resource creation.
I also checked the Resources tab, which showed the resources being created. I noticed that CloudFormation was determining the optimal order for resources to be created, such as creating the VPC before the subnet.
I waited until the status changed to CREATE_COMPLETE, refreshing occasionally to update the display.
For this task, I needed to edit the CloudFormation template to add an Amazon S3 bucket and then update the stack.
I opened the task1.yaml file I downloaded earlier and referred to the Amazon S3 Template Snippets documentation page for assistance.
Looking at the YAML example, I added the following code under the Resources header in the template:
I was careful with the indentation, using two spaces for each indent, since YAML is very particular about formatting. I didn't add any Properties since they weren't required for this basic bucket definition.
To update the stack:
After about a minute, the stack status changed from UPDATE_IN_PROGRESS to UPDATE_COMPLETE. I clicked the Resources tab and saw the bucket displayed in the list. CloudFormation had assigned it a random name to avoid conflicts with existing buckets.
I also verified the bucket creation by checking the S3 console.
This task was more complex as it required adding an Amazon EC2 instance to the template. First, I needed to add a special parameter for the Amazon Machine Image (AMI).
I updated the template by adding these lines in the Parameters section:
This parameter uses the AWS Systems Manager Parameter Store to retrieve the latest AMI for the stack's region, making it easy to deploy stacks in different regions without manually specifying an AMI ID for every region.
I learned that when writing CloudFormation templates, I could refer to other resources using the !Ref keyword. For example, I saw in the template how a VPC was defined and then referenced within the Route Table definition:
Using the AWS::EC2::Instance documentation page, I added the EC2 instance definition to my template:
I made sure to include only the five Properties listed in the requirements:
To update the stack:
Once complete, I verified the instance was displayed in the Resources tab and checked the EC2 console to see my App Server.
For the final task, I deleted the CloudFormation stack to see how it would automatically remove all resources it created.
In the CloudFormation console:
I verified that the Amazon S3 bucket, Amazon EC2 instance, and the VPC had all been properly deleted.
In conclusion, I gained practical experience with AWS CloudFormation for infrastructure as code. I learned how to:
I found CloudFormation to be a powerful tool for maintaining consistent infrastructure deployments and automating resource management. The ability to define all components in a single template makes it much easier to deploy complete environments reliably, especially during off-hours when fewer staff are available.